<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Service extends CI_Controller {

    
    function __construct() {
        parent::__construct();
        //$this->load->model(array('admodel', 'ratemodel', 'ad_comment_model'));
    }

    /**
     * @param string $ten_kenh	VMS : MobiFone, VNP : Vinaphone, VTE : Viettel
     * @param int $ma_the 	ma the cao
     * @param int $se_ri  seri the cao
     * @param string $user_name	ten nguoi dung (nguoi cao the)
     */
    public function card_web_service() {
      //error_reporting(E_ALL);
      //ini_set('error_reporting', E_ALL);
      $api_wsdl_url = "http://115.84.179.60:2222/WebServiceReceiveMO.asmx?WSDL"; // ??
    
      $client = new SoapClient($api_wsdl_url, array('trace' => 1));

      try {
        $ten_kenh = $_POST['ten_kenh'];
        $pin = $_POST['pin'];
        $seri = $_POST['seri'];
        $user_name = 'abc1';
        $api_password =  'NISCO';
        
        $result = $client->NAPTHE(array(
            'TenKenh' => $ten_kenh,
            'MaThe' => $pin,
            'SeRi' => $seri,
            'UserName' => $user_name,
            'Password' => $api_password,
        ));
    
        $responseStr = $result->NAPTHEResult;
		//echo $responseStr;
        $pos = strpos($responseStr, '$1$');
        if ($pos !== FALSE) {
    	    $this->load->model(array('usermodel', 'eventmodel'));
            $_SESSION['userLoggedIn']['point'] += 100;
            $this->usermodel->update($_SESSION['userLoggedIn']['id'], array('point' => $_SESSION['userLoggedIn']['point']));
		}
				
		$responseStr = substr($responseStr, 8, strpos($responseStr, '$') - 8);
        $this->session->set_flashdata('message', $responseStr);

        redirect('user/recharge');  
		
      } catch (Exception $e) {
        echo 'Caught exception: ',  $e->getMessage(), "\n";
      }
    }

}